//多数元素题目
//做题链接：https://leetcode.cn/problems/majority-element/description/?envType=problem-list-v2&envId=counting

//力扣提交代码部分：
class Solution {
    public int majorityElement(int[] nums) {
        int x = 0;
        int votes = 0;
        for(int i = 0;i < nums.length;i++) {
            if(votes == 0) {
                x = nums[i];
            }

            if(nums[i] == x) {
                votes++;
            }else{
                votes--;
            }
        }
        return x;
    }
}

public class demo1 {
    public static void main(String[] args) {
//        自行举的示例：
        Solution solution = new Solution();
        int[] nums = new int[]{2,4,3,3,5,3,3};
        System.out.println(solution.majorityElement(nums));
    }
}
